package com.acme.bankapp;
/**
 * TODO: Please add file description for  @fileBankApplication.java
 * Created: Nov 8, 2013 5:28:47 PM
 */

/**
 * @author Alekov Andrey
 *
 */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.acme.bankapp.account.AbstractAccount;
import com.acme.bankapp.account.CheckingAccount;
import com.acme.bankapp.account.NotEnoughFundsException;
import com.acme.bankapp.account.SavingAccount;
import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.BankException;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.ClientExistsException;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.service.bank.BankService;

public class BankApplication {
	final static Logger logger = LoggerFactory.getLogger(BankApplication.class);
	public static void main(String[] args) {
		logger.debug("Start Bank App");
		
		BankService bankService = new BankService();
		Bank myBank = new Bank("Universe Bank");
		
		Client client1 = new Client("Jonh Smith", Gender.MALE);
		Client client2 = new Client("Anna Karenina", Gender.FEEMALE);
		
		Account account1 = new CheckingAccount(100,10);
		Account account2 = new SavingAccount(100);
		
		client1.setAccount((AbstractAccount)account1);
		client2.setAccount((AbstractAccount)account2);
		
		try {
			bankService.addClient(myBank, client1);
			bankService.addClient(myBank, client2);
		} catch (ClientExistsException clientException) {
			logger.error(clientException.getMessage());
			clientException.printStackTrace();
		}
		bankService.printBalance(myBank);
		
		try {
			bankService.modifyBank(myBank, client1, -1000.0);
		} catch (NotEnoughFundsException e) {
			logger.error("Cannot modify balance.");
			e.printStackTrace();
		} catch (BankException e){
			logger.error("Bank exception.");
			e.printStackTrace();
		}
		
		try {
			bankService.modifyBank(myBank, client2, -1000.0);
		} catch (NotEnoughFundsException e){
			logger.error("Cannot modify balance");
			e.printStackTrace();

		} catch (BankException e) {
			logger.error("Bank exception.");
			e.printStackTrace();
		}
	}
}
